package com.konne.nightmare.FastPublicOpinion.ui.information.activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.konne.nightmare.FastPublicOpinion.R;
import com.konne.nightmare.FastPublicOpinion.base.BaseMvpActivity;
import com.konne.nightmare.FastPublicOpinion.base.BaseMvpPresenter;
import com.konne.nightmare.FastPublicOpinion.ui.dialog.TimeSelDialog;
import com.konne.nightmare.FastPublicOpinion.utils.LoadProgressDialog;
import com.konne.nightmare.FastPublicOpinion.widget.QJItemTitleView;

import java.util.Calendar;
import java.util.Date;

import butterknife.BindView;

/**
 * Create by ws.
 * on Data:2022/2/13  Time:下午 4:18.
 * description: 添加会议.
 */
public class AddMeetingAct extends BaseMvpActivity implements View.OnClickListener {
    @BindView(R.id.itv_timing_time)
    QJItemTitleView itv_timing_time;
    public static void start(){
        ActivityUtils.startActivity(AddMeetingAct.class);
    }
    @Override
    protected BaseMvpPresenter createPresenter() {
        return new BaseMvpPresenter();
    }

    @Override
    public int getLayout() {
        return R.layout.act_add_meeting;
    }

    @Override
    public void initView() {
        BarUtils.transparentStatusBar(this);
        BarUtils.setStatusBarLightMode(this, true);
        ((QJItemTitleView) findViewById(R.id.itv_timing)).setOnCheckedChangeListener(new QJItemTitleView.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(QJItemTitleView titleView, QJItemTitleView.Style style, boolean isChecked) {
                itv_timing_time.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            }
        });
        itv_timing_time.setOnClickListener(this);
        findViewById(R.id.itv_section).setOnClickListener(this);
        findViewById(R.id.itv_start_time).setOnClickListener(this);
        findViewById(R.id.itv_end_time).setOnClickListener(this);

        EditText et_title=findViewById(R.id.et_title);
        KeyboardUtils.registerSoftInputChangedListener(this, new KeyboardUtils.OnSoftInputChangedListener() {
            @Override
            public void onSoftInputChanged(int height) {
                if(height<=0 && et_title.getText().length()>0 ){
                    findViewById(R.id.iv_edit).setVisibility(View.VISIBLE);
                }else {
                    if(et_title.hasFocus()){
                        findViewById(R.id.iv_edit).setVisibility(View.GONE);
                    }
                }
            }
        });

    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.itv_timing_time:
                new TimeSelDialog(this).setTimeSelectListener(new TimeSelDialog.TimeSelectListener() {
                    @Override
                    public void timeSelect(String str) {
                        TextView tv_sent_time=findViewById(R.id.tv_sent_time);
                        tv_sent_time.setText(str);
                    }
                }).show();
                break;
            case R.id.itv_section:
                ImportDatabaseAct.start(0);
                break;
            case R.id.itv_end_time:
                showTimeSel((QJItemTitleView) view,false);
                break;
            case R.id.itv_start_time:
                showTimeSel((QJItemTitleView) view,true);
                break;
        }
    }
    private void showTimeSel(QJItemTitleView vp, boolean isStart) {
        Calendar selectedDate = Calendar.getInstance();
        //设置最小日期和最大日期
        Calendar startDate = Calendar.getInstance();
        Calendar endDate = Calendar.getInstance();//最大日期是今天
        startDate.set(1950, 0, 1);
        //时间选择器
        TimePickerView mStartDatePickerView = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                String text = TimeUtils.date2String(date, "yyyy-MM-dd hh:mm");
                TextView tv= (TextView) vp.getContentView().getChildAt(0);
                tv.setText(text);
            }
        })
                //年月日时分秒 的显示与否，不设置则默认全部显示
                .setType(new boolean[]{true, true, true, true, true, false})
                .setLabel("年", "月", "日", "时", "分", "")
                .isCenterLabel(false)//是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setTitleText(isStart?"开始时间":"截止时间")//标题文字
                .setTitleSize(20)//标题文字大小
                .setContentTextSize(20)//滚轮文字大小
                .setLineSpacingMultiplier(1.8f)//行间距
                .setRangDate(startDate, endDate)//设置最小和最大日期
                .setDate(selectedDate)//设置选中的日期
                .build();
        mStartDatePickerView.show();
    }
    @Override
    public LoadProgressDialog getLoadDialog() {
        return null;
    }

    @Override
    public void cancelLoadDialog() {

    }
}
